# -*- coding:utf-8 -*-

from sqlalchemy import Column, ForeignKey, Integer, DateTime, String
from sqlalchemy.orm import relationship
from config.database import BaseMixin, Base

class BgOrder(Base, BaseMixin):
    """
    订单记录表
    """
    __tablename__ = "bg_order"

    product_id = Column(Integer, nullable=False, comment='产品ID')
    product_month = Column(Integer, comment='产品周期')
    product_name = Column(String(255), nullable=False, comment='产品名称')
    product_pay = Column(Integer, comment='产品实付')
    product_price = Column(Integer, comment='产品价格')
    status = Column(String(1), nullable=False, default='0', comment='订单状态（0未支付，1已支付，2已退款）')
    user_id = Column(Integer, nullable=False, comment='用户ID')
    order_no = Column(String(50), unique=True, comment='订单号')
    payment_method = Column(String(20), default='微信支付', comment='支付方式')
    payment_time = Column(DateTime, comment='支付时间')
    refund_time = Column(DateTime, comment='退款时间')
    refund_reason = Column(String(500), comment='退款原因')
    user_name = Column(String(50), comment='用户名称')
    user_phone = Column(String(20), comment='用户手机')
    pay_wx_code = Column(String(255), nullable=False, comment='wx支付二维码')
    
    # 关联关系
    commission_records = relationship("BgAffiliateCommission", back_populates="order")


